package com.ruoyi.zyx.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.zyx.domain.ZyxMember;
import com.ruoyi.zyx.mapper.ZyxMemberDeviceMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zyx.domain.ZyxMemberDevice;
import com.ruoyi.zyx.service.IZyxMemberDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 成员基础信Controller
 *
 * @author lhs
 * @date 2021-05-31
 */
@RestController
@RequestMapping("/zyx/memberDevice")
public class ZyxMemberDeviceController extends BaseController
{
    @Autowired
    private IZyxMemberDeviceService zyxMemberDeviceService;
    @Autowired
    private ZyxMemberDeviceMapper zyxMemberDeviceMapper;
    /**
     * 查询成员基础信列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ZyxMemberDevice zyxMemberDevice)
    {
        startPage();
        List<ZyxMemberDevice> list = zyxMemberDeviceService.selectZyxMemberDeviceList(zyxMemberDevice);
        return getDataTable(list);
    }


    @GetMapping("/listManageMember")
    public AjaxResult listManageMember(ZyxMemberDevice zyxMemberDevice)
    {
        zyxMemberDevice.setDepartid(SecurityUtils.getLoginUser().getUser().getDeptId());//我所在的维修公司
        List<ZyxMemberDevice> list = zyxMemberDeviceMapper.selectManageMemberList(zyxMemberDevice);

        return  AjaxResult.success(list);
    }

    /**
     * 导出成员基础信列表
     */
    @PreAuthorize("@ss.hasPermi('zyx:memberDevice:export')")
    @Log(title = "成员基础信", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZyxMemberDevice zyxMemberDevice)
    {
        List<ZyxMemberDevice> list = zyxMemberDeviceService.selectZyxMemberDeviceList(zyxMemberDevice);
        ExcelUtil<ZyxMemberDevice> util = new ExcelUtil<ZyxMemberDevice>(ZyxMemberDevice.class);
        return util.exportExcel(list, "成员基础信数据");
    }

    /**
     * 获取成员基础信详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zyxMemberDeviceService.selectZyxMemberDeviceById(id));
    }
    /**
     * 查询成员设备信息
     */
    @GetMapping(value = "/memberDeviceTreeselect/{id}")
    public AjaxResult memberDeviceTreeselect(@PathVariable("id") Long id)
    {

        return AjaxResult.success(zyxMemberDeviceService.memberDeviceTreeselect(id));
    }

    /**
     * 新增成员基础信
     */
    @PreAuthorize("@ss.hasPermi('zyx:memberDevice:add')")
    @Log(title = "成员基础信", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyxMemberDevice zyxMemberDevice)
    {
        return toAjax(zyxMemberDeviceService.insertZyxMemberDevice(zyxMemberDevice));
    }

    /**
     * 修改成员基础信
     */
    @PreAuthorize("@ss.hasPermi('zyx:memberDevice:edit')")
    @Log(title = "成员基础信", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyxMemberDevice zyxMemberDevice)
    {
        return toAjax(zyxMemberDeviceService.updateZyxMemberDevice(zyxMemberDevice));
    }

    /**
     * 删除成员基础信
     */
    @Log(title = "成员基础信", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zyxMemberDeviceService.deleteZyxMemberDeviceByIds(ids));
    }


    @PostMapping("/addMemberDevice")
    public AjaxResult addMemberDevice(@RequestBody ZyxMemberDevice zyxMemberDevice)
    {
        return toAjax(zyxMemberDeviceService.addMemberDevice(zyxMemberDevice));
    }
}
